package com.crm.service.system.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.crm.domain.entity.Role;
import com.crm.domain.query.RoleQuery;
import com.crm.mapper.RoleMapper;
import com.crm.service.system.RoleService;
import org.springframework.stereotype.Service;

@Service
public class RoleServiceImpl extends ServiceImpl<RoleMapper, Role> implements RoleService {
    @Override
    public Page<Role> queryPage(RoleQuery query) {

        Page<Role> page = Page.of(query.getPageNum(), query.getPageSize());

        LambdaQueryWrapper<Role> wrapper = Wrappers.<Role>lambdaQuery()
                .eq(query.getStatus()!=null,Role::getStatus, query.getStatus())
                .like(query.getRoleName()!=null ,Role::getRoleName, query.getRoleName())
                .like(query.getRoleKey()!=null ,Role::getRoleKey, query.getRoleKey())
                .between(query.getBeginCreateTime()!=null && query.getEndCreateTime()!=null,Role::getCreateTime, query.getBeginCreateTime(), query.getEndCreateTime());
      Page<Role> cluePage = page(page, wrapper);
      return cluePage;
    }
}
